# 功能：修改文件夹下的txt文件里面的某个字符或者字符串
from glob import glob
from tqdm import tqdm
fd = r'C:\Users\Administrator\Downloads\gt'
file_txt = glob(fd + '/*.txt')
old_str = 'a'
new_str = 'haier'
file_data = ''
for file in tqdm(file_txt):
    with open(file, "r", encoding="utf-8") as f:
        for line in f:
            if old_str  in line:
                line = line.replace(old_str, new_str)
            file_data += line
    with open(file, "w", encoding="utf-8") as f:
        f.write(file_data)
